package com.example.springaop.proxy;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.InvocationHandler;

import java.lang.reflect.Proxy;

public class Main {
    public static void main(String[] args) {
      /*  RealSubjectHouse realSubjectHouse=new RealSubjectHouse();
        HouseProxy houseProxy=new HouseProxy(realSubjectHouse);

        houseProxy.rentHouse();*/

        RealSubjectHouse target = new RealSubjectHouse();
        //动态生成代理对象  代理接口, 运行成功
       /* SubjectHouse proxy= (SubjectHouse) Proxy.newProxyInstance(
                SubjectHouse .class.getClassLoader(),
                new Class[]{SubjectHouse .class},
                new JDKInvocationHandler(target));
        proxy.rentHouse();*/


        SubjectHouse houseSubject = (SubjectHouse) Enhancer.create(
                target.getClass(), new CGLibMethodInterceptor(target));
        houseSubject.rentHouse();
    }
}
